<template>
  <el-dialog
    :visible.sync="dialog"
    :loading="loading"
    :close-on-click-modal="false"
    :title="titleMap[dialogStatus]"
    width="75%"
    left
    @close="closeDlg"
  >
    <div style="padding-top:5px">
      <el-button size="mini" type="primary" style="float:right;margin-bottom:5px;margin-left:0px;" icon="el-icon-search" round @click="toQuery">刷新</el-button>
      <el-table :data="data" stripe size="small" border style="width: 100%;">
        <el-table-column label="编号" prop="id" :width="48" />
        <el-table-column label="表名" prop="listName" :width="230" />
        <el-table-column label="本地文件路径" prop="desciption" />
        <el-table-column label="最后更新时间" prop="updatedTime" :width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.updatedTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="185">
          <template slot-scope="scope">
            <el-button v-if="scope.row.desciption !='系统本地表：FRESH_FOOD_PI_FINELINE'" size="mini" type="primary" icon="el-icon-refresh-right" round :disabled="disabled=!show" @click="syncDataCommon(scope.row.listName)">
              <span v-show="show">同步数据</span>
              <span v-show="!show" class="count">{{ count }} s</span>
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </el-dialog>
</template>

<script>
// import { syncWindIdListData } from '@/api/rule2'
import { syncListDataCommon } from '@/api/excelDataCommon'
import { Message } from 'element-ui'
import { parseTime } from '@/utils/index'
import { queryDetailList } from '@/api/excelDataCommon'

export default {
  components: {
  },
  props: {
    parent: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      titleMap: {
        listMsg: '清单同步管理'
      },
      ruleInfo: {
      },
      show: true, // 初始启用按钮
      count: '', // 初始化次数
      data: [],
      loading: false,
      dialog: false,
      dialogStatus: ''
    }
  },
  created() {
  },
  methods: {
    parseTime,
    closeDlg() {
      this.dialog = false
    },
    // 查询
    toQuery() {
      queryDetailList(this.params).then(res => {
        this.data = res
      })
    },
    syncDataCommon(row) {
      syncListDataCommon(row).then(res => {
        Message({
          message: '同步任务启动成功',
          type: 'success',
          duration: 3 * 1000
        })
      })
      const TIME_COUNT = 60
      if (!this.timer) {
        this.count = TIME_COUNT
        this.show = false
        this.timer = setInterval(() => {
          if (this.count > 0 && this.count <= TIME_COUNT) {
            this.count--
          } else {
            this.show = true
            clearInterval(this.timer) // 清除定时器
            this.timer = null
          }
        }, 1000)
      }
    }
  }
}
</script>

